package com.tudouji.project.mt.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.project.mt.domain.MtGoodsDue;
import com.tudouji.project.mt.service.IMtGoodsDueService;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.web.page.TableDataInfo;

/**
 * 美团替代料对应关系Controller
 * 
 * @author tudouji
 * @date 2024-02-21
 */
@RestController
@RequestMapping("/mt/due")
public class MtGoodsDueController extends BaseController
{
    @Autowired
    private IMtGoodsDueService mtGoodsDueService;

    /**
     * 查询美团替代料对应关系列表
     */
    @PreAuthorize("@ss.hasPermi('mt:due:list')")
    @GetMapping("/list")
    public TableDataInfo list(MtGoodsDue mtGoodsDue)
    {
        startPage();
        List<MtGoodsDue> list = mtGoodsDueService.selectMtGoodsDueList(mtGoodsDue);
        return getDataTable(list);
    }

    /**
     * 导出美团替代料对应关系列表
     */
    @PreAuthorize("@ss.hasPermi('mt:due:export')")
    @Log(title = "美团替代料对应关系", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MtGoodsDue mtGoodsDue)
    {
        List<MtGoodsDue> list = mtGoodsDueService.selectMtGoodsDueList(mtGoodsDue);
        ExcelUtil<MtGoodsDue> util = new ExcelUtil<MtGoodsDue>(MtGoodsDue.class);
        return util.exportExcel(list, "due");
    }

    /**
     * 获取美团替代料对应关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('mt:due:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mtGoodsDueService.selectMtGoodsDueById(id));
    }

    /**
     * 新增美团替代料对应关系
     */
    @PreAuthorize("@ss.hasPermi('mt:due:add')")
    @Log(title = "美团替代料对应关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MtGoodsDue mtGoodsDue)
    {
        if (!mtGoodsDueService.exist(mtGoodsDue.getMtGoodsCode(), mtGoodsDue.getMtGoodsCodeDue())){
            return AjaxResult.error("已存在替代料对应关系！");
        }
        return toAjax(mtGoodsDueService.insertMtGoodsDue(mtGoodsDue));
    }

    /**
     * 修改美团替代料对应关系
     */
    @PreAuthorize("@ss.hasPermi('mt:due:edit')")
    @Log(title = "美团替代料对应关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MtGoodsDue mtGoodsDue)
    {
        if (!mtGoodsDueService.exist(mtGoodsDue.getMtGoodsCode(), mtGoodsDue.getMtGoodsCodeDue())){
            return AjaxResult.error("已存在替代料对应关系！");
        }
        return toAjax(mtGoodsDueService.updateMtGoodsDue(mtGoodsDue));
    }

    /**
     * 删除美团替代料对应关系
     */
    @PreAuthorize("@ss.hasPermi('mt:due:remove')")
    @Log(title = "美团替代料对应关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mtGoodsDueService.deleteMtGoodsDueByIds(ids));
    }
}
